package cn.edu.scau.serviceImpl;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import cn.edu.scau.dao.SingleDao;
import cn.edu.scau.daoImpl.SingleDaoImpl;
import cn.edu.scau.daoImpl.WorkDaoImpl;
import cn.edu.scau.entity.Single;
import cn.edu.scau.entity.Work;
import cn.edu.scau.service.SingleService;

/**
 * Single业务逻辑层（包括校科联章程，CI，历届成员）
 * 
 * @author cxywan
 *
 */
@Service("singleServiceImpl")
public class SingleServiceImpl implements SingleService<Single> {

	/**
	 * 持久化层
	 */
	@Autowired
	private SingleDao singleDao;

	public SingleDao getSingleDao() {
		return singleDao;
	}

	public void setSingleDao(SingleDao singleDao) {
		this.singleDao = singleDao;
	}

	/**
	 * 保存实体
	 * 
	 * @param entity
	 *            Single实体
	 */
	@Override
	public void add(Single entity) {

		this.getSingleDao().save(entity);

	}

	/**
	 * 删除实体
	 * 
	 * @param entity
	 *            Single 实体
	 * 
	 */
	public boolean delete(Single entity,Integer id) {

		if (this.getSingleDao().find(Single.class, id) != null) {
			this.getSingleDao().delete(entity);
			return true;
		}

		return false;

	}

	/**
	 * 根据id删除实体
	 * 
	 * @param id
	 *            Single实体的id
	 * 
	 */
	@Override
	public boolean delete(Integer id) {
		if (this.getSingleDao().find(Single.class, id) != null) {
			this.getSingleDao().delete(Single.class, id);
			return true;
		}
		return false;
	}

	/**
	 * 更新实体
	 * 
	 * @param entity
	 *            Single 实体
	 */
	@Override
	public boolean update(Single entity,Integer id) {

		if (this.getSingleDao().find(Single.class, id) != null) {
			this.getSingleDao().update(entity);
			return true;
		}

		return false;

	}

	/**
	 * 根据id获取实体
	 * 
	 * @param id
	 *            Single 实体的id
	 * @return
	 */
	@Override
	public Single getSingleByID(Integer id) {

		return this.getSingleDao().find(Single.class, id);
	}

	/**
	 * 根据栏目id获取实体
	 * 
	 * @param columnID
	 *            栏目id
	 * 
	 * @return
	 *
	 */
	@Override
	public Single getSingleEntityByColumnID(Integer columnID) {

		return ((SingleDaoImpl) this.getSingleDao()).getSingleEntityByColumnID(columnID);
	}

	/**
	 * 获取所有的Single实体
	 * 
	 */
	@Override
	public List<Single> getSingles() {

		return this.getSingleDao().findAll(Single.class);

	}

	@Override
	public List showTheEntity(String type, Integer columnId, Integer id, Integer pageNo, boolean frontOrBackground) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public long countTheEntityNum(Integer columnId, Integer pageSize, boolean frontOrBackground) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public List<String> saveImage(MultipartFile[] files, HttpServletRequest request, String releaseDate) {
		// TODO Auto-generated method stub
		return null;
	}

}
